home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
tex
/
td187src.lzh
/
HPGL.I
< prev
next >
Wrap
Text File
|
1991-12-14
|
42KB
|
1,490 lines
IMPLEMENTATION MODULE HPGL ;
(*
Versuch, ein bereits fertiges HPGL-File zu interpretieren
und die Objekte zu übernehmen. Quick'n Dirty-Version.
Verbesserungen überall möglich und nötig... (JP)
Die allgemeine Syntax eines HPGL-Befehles lautet:
XX{a1{,a2{...}}}{;}
wobei XX ein zweibuchstabiges Kommando in Großschrift ist, worauf
kein, ein oder mehrere Parameter, durch Kommata voneinander ge-
trennt, folgen. Der Befehl wird durch ein ";" abgeschlossen bzw.
es folgt unmittelbar darauf der nächste Befehl.
Die Befehlsübersicht und ihre Syntax wurden der c't-Kartei 1/1990
auf S.335-342 entnommen.
Dieses Modul ist (C)'90 by Jens Pirnay
*)
(*
Letzte Änderung: - 17/04/91 13:01 Änderungen bei:
(1) PlotText (Adresse von Cptr eingesetzt)
(2) ComputeDirect (arctan(0) vermieden)
(3) GetIntNumber,
GetRealNumber (eofcmd besser gesetzt)
*)
FROM Dialoge IMPORT BusyStart, BusyEnd;
FROM Diverses IMPORT min, max, round, GetFSelText, NumAlert;
FROM FileIO IMPORT Fopen, EOF, AgainChar, Reset, Close, ReadChar;
FROM ObjectUtilities IMPORT FillObject;
FROM Types IMPORT DrawObjectTyp, TextPosTyp, CodeAryTyp,
ObjectPtrTyp, ExtendedPtrTyp,
CharArraySize, ExtendedArraySize ;
FROM SYSTEM IMPORT BYTE, WORD, ADDRESS , ADR ;
IMPORT CommonData ;
IMPORT GetFile;
IMPORT MathLib0 ;
IMPORT MagicConvert ;
IMPORT MagicDOS ;
IMPORT MagicStrings ;
IMPORT MagicSys ;
IMPORT Variablen ;
IMPORT mtAlerts;
FROM VectorFont IMPORT LoadFont, TextWidth, TextHeight, SetTextStyle,
SetFont, OutText, CreateText;
(**
IMPORT Debug;
IMPORT RTD;
**)
CONST MaxParams = 15; (* Sollte in jedem Falle langen *)
MaxCommand = 57; (* Die meisten Kommandos brauchen wir nie ! *)
CR = 15C;
LF = 12C;
FF = 14C;
TYPE ParseRec = RECORD
cmd : ARRAY [0..2] OF CHAR;
Action : PROC;
END;
chset = SET OF CHAR;
linetyp = (SolidLn, DottdLn, DashdLn);
VAR Linetype : linetyp;
textpos : TextPosTyp;
(* NoJust, LeftTop, Left, LeftBot, Top,
Center, Bottom, RightTop, Right, RightBot *)
Command : ARRAY [0..2] OF CHAR;
ParamTail : ARRAY [0..255] OF CHAR;
WholeParams : ARRAY [0..255] OF CHAR;
StrParams : ARRAY [1..MaxParams] OF ARRAY [0..59] OF CHAR;
Parse : ARRAY [1..MaxCommand] OF ParseRec;
ValParams : ARRAY [1..MaxParams] OF INTEGER;
CurrentParam : CARDINAL; (* gibt die Zahl der aktuellen Parameter an *)
currcmd : CARDINAL;
currentend : CHAR;
EndCharacter : CHAR;
CurrentXPos : INTEGER;
CurrentYPos : INTEGER;
Filehandle : INTEGER;
Filltype : INTEGER;
P1x, P1y, P2x, P2y : INTEGER;
ScP1x, ScP1y,
ScP2x, ScP2y : INTEGER; (* In User-Units *)
Thickness : INTEGER;
writeangle : INTEGER;
Xtxtsize, Ytxtsize : LONGREAL;
charslant : LONGREAL;
charheigth : LONGREAL; (* = % von P2y - P1y *)
charwidth : LONGREAL; (* = % von P2x - P1x *)
PenUp : BOOLEAN;
ScaleMode : BOOLEAN;
ThereWasAPoint : BOOLEAN;
error : BOOLEAN;
LineToAdd : CodeAryTyp;
(* ----------------------------------------------------------------- *)
(* $D+*)
PROCEDURE GobbleSpaces;
VAR c : CHAR;
BEGIN
REPEAT
ReadChar(Filehandle, c);
UNTIL EOF OR NOT (c IN chset{' ',03C,CR,LF});
(**
RTD.ShowVar('Gobble now:', c);
**)
AgainChar := NOT EOF;
(**
RTD.Message('Leaving GobbleSpaces');
**)
END GobbleSpaces;
(* $D-*)
(* ----------------------------------------------------------------- *)
PROCEDURE ReadCommand(VAR command : ARRAY OF CHAR);
VAR result : ARRAY [0..2] OF CHAR;
last1, last2 : CHAR;
BEGIN
GobbleSpaces;
result := ' ';
last1 := 0C;
last2 := 0C;
LOOP
REPEAT
last2 := last1;
last1 := result[0];
ReadChar(Filehandle, result[0]);
UNTIL EOF OR ((result[0]>='A') AND (result[0]<='Z'));
(**
RTD.ShowVar('Cmd-Char:', result[0]);
**)
error := NOT (result[0]>='A') AND (result[0]<='Z');
IF NOT EOF AND NOT error THEN
ReadChar(Filehandle, result[1]);
IF (last2=CHR(27)) AND (last1=CHR(46)) THEN
(* nur bei <1B 2E> Spezialfall *)
IF (result[1]>='A') AND (result[1]<='Z') THEN
EXIT;
END;
ELSE
EXIT;
END;
ELSE
result := '';
EXIT;
END;
END;
(**
RTD.Message(result);
**)
MagicStrings.Assign(result, command);
(**
RTD.Message('Leaving ReadCommand');
**)
END ReadCommand;
(* ----------------------------------------------------------------- *)
PROCEDURE ReadEndOfCommand;
VAR c : CHAR;
index : INTEGER;
cset : chset;
BEGIN
cset := chset{03C,CR,LF,FF,'A'..'Z'};
INCL(cset, currentend);
index := 0;
REPEAT
ReadChar(Filehandle, c);
WholeParams[index] := c;
INC(index, 1);
UNTIL EOF OR (c IN cset);
IF c IN chset{'A'..'Z'} THEN
AgainChar := TRUE;
END;
WholeParams[index] := 0C;
(**
RTD.Message('EOFcomm:');
RTD.Message(WholeParams);
RTD.Message('Leaving ReadEndOfCommand');
**)
END ReadEndOfCommand;
(* ----------------------------------------------------------------- *)
PROCEDURE TexValueX(plotvalue : INTEGER) : INTEGER;
(* Rechne die Plotter-Koordinaten in vernünftiges System um:
Plotterauflösung beträgt 0.025 mm = 1/40 mm
*)
VAR res : INTEGER;
rres : LONGREAL;
BEGIN
IF ScaleMode THEN
(**
RTD.Message('sc-mode');
**)
res := round(
MathLib0.real(P2x-P1x)/MathLib0.real(ScP2x-ScP1x)*
MathLib0.real(plotvalue-ScP1x)
) + P1x;
ELSE
res := plotvalue;
END;
(**
RTD.ShowVar('pv', plotvalue);
RTD.ShowVar('tx', res);
RTD.Message('L. TVX');
**)
RETURN res;
END TexValueX;
PROCEDURE TexValueY(plotvalue : INTEGER) : INTEGER;
(* Rechne die Plotter-Koordinaten in vernünftiges System um:
Plotterauflösung beträgt 0.025 mm = 1/40 mm
*)
VAR res : INTEGER;
rres : LONGREAL;
BEGIN
IF ScaleMode THEN
(**
RTD.Message('sc-mode');
**)
res := round(
MathLib0.real(P2y-P1y)/MathLib0.real(ScP2y-ScP1y)*
MathLib0.real(plotvalue-ScP1y)
) + P1y;
ELSE
res := plotvalue;
END;
(**
RTD.ShowVar('pv', plotvalue);
RTD.ShowVar('ty', res);
RTD.Message('L. TVY');
**)
RETURN res;
END TexValueY;
(* ----------------------------------------------------------------- *)
(* $D+*)
PROCEDURE GetIntNumber(VAR str : ARRAY OF CHAR;
VAR intval : INTEGER;
VAR eofcmd : BOOLEAN);
VAR result : ARRAY [0..127] OF CHAR;
c : CHAR;
index : INTEGER;
ok : BOOLEAN;
BEGIN
GobbleSpaces;
index := 0;
REPEAT
ReadChar(Filehandle, c);
result[index] := c;
INC(index, 1);
UNTIL EOF OR NOT (c IN chset{'0'..'9','+','-'});
result[index-1] := 0C;
eofcmd := (c =';') OR (c=03C) OR ((c>='A') AND (c<='Z'));
IF NOT EOF THEN
IF (c<>',') AND (c<>';') AND (c<>03C) THEN
AgainChar := TRUE;
END;
(**
ELSE
eofcmd := TRUE;
**)
END;
MagicStrings.Assign(result, str);
intval := MagicConvert.StrToInt(str);
(**
RTD.ShowVar('IntVal :', intval);
RTD.Message(result);
RTD.Message('Leaving GetIntNumber');
**)
END GetIntNumber;
(* $D-*)
PROCEDURE GetRealNumber(VAR str : ARRAY OF CHAR;
VAR realval : LONGREAL;
VAR eofcmd : BOOLEAN);
VAR re